# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=procdump
pkgver=3.5.0.r1.g7a0392b
pkgrel=1
epoch=1
pkgdesc='Generate coredumps based off performance triggers.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-binary' 'blackarch-misc')
url='https://github.com/Microsoft/ProcDump-for-Linux'
license=('MIT')
depends=('gdb')
makedepends=('git' 'cmake' 'clang' 'bpf' 'libbpf')
source=("$pkgname::git+https://github.com/Microsoft/ProcDump-for-Linux.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  sed -i 's/-D_FORTIFY_SOURCE=2//g;s/-U_FORTIFY_SOURCE//g' CMakeLists.txt
}

build() {
  cd $pkgname

  mkdir -p build
  cd build
  cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    ..

  make
}

package() {
  cd $pkgname

  install -Dm 755 "build/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" *.md
  install -Dm 644 "$pkgname.1" "$pkgdir/usr/share/man/man1/$pkgname.1"
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

